/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * WaitingFrame.java
 *
 * Created on Jun 25, 2009, 8:01:07 PM
 */

package ces31.ChineseDicesClient.IU;

import ces31.ChineseDicesClient.RN.RN_Jogo;
import ces31.ChineseDicesClient.SO_SistemaCliente;
import ces31.ChineseDicesClient.SO_SistemaCliente_Facade;

/**
 *
 * @author Anderson Aiziro
 */
public class IU_Espera extends javax.swing.JFrame {

    /** Creates new form WaitingFrame */
    public IU_Espera() {
        initComponents();
        this.setVisible(true);
    }

    public RN_Jogo iniciarJogo(SO_SistemaCliente_Facade clienteFacade, String nomeJogador, String nomeAdversario) {
        this.setVisible(false);
        IU_Jogo jogoinicial = new IU_Jogo();
        return jogoinicial.iniciarJogo(clienteFacade, nomeJogador, nomeAdversario);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mensagemEspera = new javax.swing.JLabel();
        imagemEspera = new javax.swing.JLabel();
        botaoSair = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        mensagemEspera.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        mensagemEspera.setText("Esperando adversário.");
        mensagemEspera.setName("mensagemEspera"); // NOI18N

        imagemEspera.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ces31/ChineseDicesClient/IU/busy-icon0.png"))); // NOI18N
        imagemEspera.setName("imagemEspera"); // NOI18N

        botaoSair.setText("Sair");
        botaoSair.setName("botaoSair"); // NOI18N
        botaoSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarConexao(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(botaoSair)
                    .addComponent(mensagemEspera))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(imagemEspera)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(imagemEspera)
                    .addComponent(mensagemEspera))
                .addGap(18, 18, 18)
                .addComponent(botaoSair)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
/**
 * Caso de Uso: Sair da Sala de Espera
 * @param evt
 */
    private void cancelarConexao(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarConexao
        this.setVisible(false);
        try {
            SO_SistemaCliente.getSalaDeEspera().desconectarCliente();
        } catch (Throwable ex) {
            //Logger.getLogger(IU_Espera.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_cancelarConexao


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoSair;
    private javax.swing.JLabel imagemEspera;
    private javax.swing.JLabel mensagemEspera;
    // End of variables declaration//GEN-END:variables

}
